home *** CD-ROM | disk | FTP | other *** search
- { child.pas -- Demonstrate child windows }
-
- program Child;
-
- {$R child.res}
-
- uses WinTypes, WinProcs, WObjects;
-
- const
-
- id_Menu = 100; { Menu resource ID }
- cm_Open = 101; { Command IDs }
- cm_Close = 102;
- cm_Quit = 103;
-
- type
-
- ChildApplication = object(TApplication)
- procedure InitMainWindow; virtual;
- end;
-
- PMainWindow = ^MainWindow;
- PChildWindow = ^ChildWindow;
-
- MainWindow = object(TWindow)
- MyChild: PChildWindow;
- constructor Init(AParent: PWindowsObject; ATitle: PChar);
- procedure CMOpen(var Msg: TMessage);
- virtual cm_First + cm_Open;
- procedure CMClose(var Msg: TMessage);
- virtual cm_First + cm_Close;
- procedure CMQuit(var Msg: TMessage);
- virtual cm_First + cm_Quit;
- procedure ParentNotify(var Msg: TMessage);
- virtual wm_First + wm_ParentNotify;
- procedure WMLButtonDown(var Msg: TMessage);
- virtual wm_First + wm_LButtonDown;
- end;
-
- ChildWindow = object(TWindow)
- MyParent: PMainWindow;
- constructor Init(AParent: PWindowsObject;
- ATitle: PChar; AStyle: LongInt);
- destructor Done; virtual;
- procedure WMLButtonDown(var Msg: TMessage);
- virtual wm_First + wm_LButtonDown;
- end;
-
-
- { ChildApplication }
-
- {- Initialize ChildApplication object's window }
- procedure ChildApplication.InitMainWindow;
- begin
- MainWindow := New(PMainWindow, Init(nil, 'Child Window Demo'))
- end;
-
-
- { MainWindow }
-
- {- Construct MainWindow object }
- constructor MainWindow.Init(AParent: PWindowsObject; ATitle: PChar);
- begin
- TWindow.Init(AParent, ATitle);
- Attr.Menu := LoadMenu(HInstance, PChar(id_Menu));
- MyChild := nil
- end;
-
- {- Reopen the child windows }
- procedure MainWindow.CMOpen(var Msg: TMessage);
- begin
- if MyChild <> nil then
- SetFocus(MyChild^.HWindow)
- else
- MyChild := PChildWindow(
- Application^.MakeWindow(New(PChildWindow,
-
- Init(@Self, 'Normal Child',
- ws_Child or ws_Visible or ws_OverlappedWindow))))
-
- (* Note: Before implementing these two alternate child windows,
- make MyChild a global variable and modify ChildWindow.Done
- to set that variable to nil directly rather than via the
- MyParent pointer.
-
- Init(@Self, 'Child With Parent',
- ws_Popup or ws_Visible or ws_OverlappedWindow))))
-
- Init(nil, 'Child Without Parent',
- ws_Popup or ws_Visible or ws_OverlappedWindow))))
- *)
- end;
-
- {- Close the child windows }
- procedure MainWindow.CMClose(var Msg: TMessage);
- begin
- if MyChild <> nil then
- begin
- MyChild^.CloseWindow;
- MyChild := nil
- end
- end;
-
- {- Quit the application }
- procedure MainWindow.CMQuit(var Msg: TMessage);
- begin
- CloseWindow { Also closes any open child windows }
- end;
-
- {- Runs when child is created, destroyed, or selected }
- procedure MainWindow.ParentNotify(var Msg: TMessage);
- begin
- if Msg.WParam = wm_Destroy then
- MyChild := nil
- end;
-
- {- Respond to left mouse button click in parent }
- procedure MainWindow.WMLButtonDown(var Msg: TMessage);
- begin
- MessageBox(HWindow, 'Inside main window', 'Left Button', mb_Ok)
- end;
-
-
- { ChildWindow }
-
- {- Construct child window object }
- constructor ChildWindow.Init(AParent: PWindowsObject;
- ATitle: PChar; AStyle: LongInt);
- begin
- TWindow.Init(AParent, ATitle);
- MyParent := PMainWindow(AParent);
- with Attr do
- begin
- Style := AStyle and not ws_SysMenu;
- X := 0; Y := 0; W := 250; H := 150
- end
- end;
-
- {- Destroy child window }
- destructor ChildWindow.Done;
- begin
- if MyParent <> nil then
- MyParent^.MyChild := nil;
- TWindow.Done
- end;
-
- {- Respond to left mouse button click in child }
- procedure ChildWindow.WMLButtonDown(var Msg: TMessage);
- begin
- MessageBox(HWindow, 'Inside child window', 'Left Button', mb_Ok)
- end;
-
- var
-
- ChildApp: ChildApplication;
-
- begin
- ChildApp.Init('ChildApp');
- ChildApp.Run;
- ChildApp.Done
- end.
-
-
- {--------------------------------------------------------------
- Copyright (c) 1991 by Tom Swan. All rights reserved.
- Revision 1.00 Date: 5/8/1991
- ---------------------------------------------------------------}
-